package cn.gzjp.modules.dt.entity;

import cn.gzjp.common.config.ConfigUtils;
import cn.gzjp.common.utils.StringUtil;
import cn.gzjp.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.Length;

import cn.gzjp.common.persistence.DataEntity;
import cn.gzjp.common.utils.excel.annotation.ExcelField;

import java.util.Date;
import java.util.List;

/**
 * 题目Entity
 * @author zengcp
 * @version 2018-02-24
 */
public class Question extends DataEntity<Question> {
	
	private static final long serialVersionUID = 1L;
	private Integer questionId;		// 题目id
	private String title;		// 题目
	private String pic;		// 题目图片
	private String answer;		// 答案
	private String type;		// 题目类型1单选2多选3判断
	private String category;		// 题目类别
	private String memo;		// 解析
	private Integer sn;

	private List<QuestionOption> options;//选项
	
	public Question() {
		super();
	}

	public Question(Integer questionId){
		this.questionId = questionId;
	}

	@ExcelField(title="题目id", align=2, sort=0)
	@JsonIgnore
	public Integer getQuestionId() {
		return questionId;
	}

	public void setQuestionId(Integer questionId) {
		this.questionId = questionId;
	}
	
	@Length(min=0, max=256, message="题目长度必须介于 0 和 256 之间")
	@ExcelField(title="题目", align=2, sort=1)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	@Length(min=0, max=128, message="题目图片长度必须介于 0 和 128 之间")
	@ExcelField(title="题目图片", align=2, sort=2)
	@JsonIgnore
	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}
	public String getPicUrl() {
		if (StringUtils.isNotBlank(pic)) {
			if(pic.startsWith("http")){
				return pic;
			}else{
				String photoUrl = ConfigUtils.getProperty("photoUrl");
				return photoUrl +"/userfiles/drivetest/"+ pic;
			}
		}
		return "";
	}
	
	@Length(min=0, max=2, message="答案长度必须介于 0 和 2 之间")
	@ExcelField(title="答案", align=2, sort=3)
	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}
	
	@Length(min=0, max=1, message="题目类型1单选2多选3判断长度必须介于 0 和 1 之间")
	@ExcelField(title="题目类型1单选2多选3判断", dictType="question_type", align=2, sort=4)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@Length(min=0, max=1, message="题目类别长度必须介于 0 和 1 之间")
	@ExcelField(title="题目类别", align=2, sort=5)
	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}
	
	@Length(min=0, max=256, message="解析长度必须介于 0 和 256 之间")
	@ExcelField(title="解析", align=2, sort=6)
	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public List<QuestionOption> getOptions() {
		return options;
	}

	public void setOptions(List<QuestionOption> options) {
		this.options = options;
	}

	@JsonIgnore
	public String getId(){
		return this.id;
	}
	@JsonIgnore
	public Date getCreateDate() {
		return createDate;
	}

	public Integer getSn() {
		return sn;
	}

	public void setSn(Integer sn) {
		this.sn = sn;
	}
}